package com.sam;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import com.jess.arms.utils.ArmsUtils;
import com.sam.api.cache.CommCache;
import com.sam.api.service.UserService;
import com.sam.mvp.entity.User;
import com.sam.utils.Log;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;
import java.util.function.Consumer;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;
import io.rx_cache2.DynamicKey;
import io.rx_cache2.EvictDynamicKey;

import static org.junit.Assert.assertEquals;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.sam", appContext.getPackageName());
        Observable.just(ArmsUtils.obtainAppComponentFromContext(appContext)
                .repositoryManager()
                .obtainRetrofitService(UserService.class)
                .getUsers(0, 10))
                .flatMap((Function<Observable<List<User>>, ObservableSource<List<User>>>) listObservable ->
                        ArmsUtils.obtainAppComponentFromContext(appContext)
                                .repositoryManager()
                                .obtainCacheService(CommCache.class)
                                .getUsers(listObservable, new DynamicKey(0), new EvictDynamicKey(true))
                                .map(listReply -> listReply.getData())
                );


    }
}
